#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/10/25
# @Author  : 邓大大
# @Desc    : API获取行情，pandas分析行情
import json

import requests
import datetime
import pandas as pd

pd.set_option('expand_frame_repr', False)


def get_single_ticker_data(symbol):
    """
    单个交易对的ticker数据获取
    """
    proxies = {
        "http": "http://127.0.0.1:58591",
        "https": "https://127.0.0.1:58591",
    }
    ticker_url = 'https://www.okex.com/api/spot/v3/instruments/{}/ticker'.format(symbol)
    res_obj = requests.get(ticker_url, proxies=proxies)
    res_json = res_obj.json()
    # data = json.dumps(res_json).replace('instrument_id', "币对").replace('last', '最新成交价').replace('last_qty', '最新成交的数量'). \
    #     replace('best_ask_size', '卖一价对应的量').replace(
    #     'best_ask', '卖一价').replace('best_bid_size', '买一价对应的数量').replace('best_bid', '买一价').replace(
    #     'open_24h', '24小时开盘价'). \
    #     replace('high_24h', '24小时最高价').replace('low_24h', '24小时最低价').replace('base_volume_24h',
    #                                                                          '24小时成交量，按交易货币统计').replace(
    #     'quote_volume_24h', '24小时成交量，按计价货币统计'). \
    #     replace('timestamp', '系统时间戳').replace('open_utc0', 'UTC 0 时开盘价').replace('open_utc8', 'UTC+8 时开盘价')
    # res_json = eval(data)
    # print(obj_json.values())
    raw_df = pd.DataFrame(index=[0], columns=list(res_json.keys())[0:-5])
    raw_df[list(res_json.keys())[0:-5]] = list(res_json.values())[0:-5]
    print(raw_df)


def main():
    """
    主函数
    """
    symbol = 'btc_usdt'
    ticker_df = get_single_ticker_data(symbol)


if __name__ == '__main__':
    get_single_ticker_data('btc_usdt')
